public class test {
    //leetcode 27.移除元素(双指针法)
    class Solution {
        public static int removeElement(int[] nums, int val) {
            int num = nums.length;
            int left = 0;
            int right = nums.length - 1;
            for(left = 0;left <= right;left++){
                while(left <= right && nums[right] == val){
                    right--;
                }
                while(left <= right && nums[left] != val){
                    left++;
                }
                if(left < right){
                    int tmp = nums[left];
                    nums[left] = nums[right];
                    nums[right] = tmp;
                }
            }
            return right + 1;
        }
    }
    //leetcode 283.移动零
    class Solution {
        public void moveZeroes(int[] nums) {
            int left = 0;
            int right = 0;
            for(right = 0;right < nums.length;right++){
                if(nums[right] != 0){
                    int tmp = nums[right];
                    nums[right] = nums[left];
                    nums[left] = tmp;
                    left++;
                }
            }
        }
    }
    //leetcode 1089.复写零
    class Solution {
        public void duplicateZeros(int[] arr) {
            int len = arr.length;
            int cur = 0;
            int dest = -1;
            //查找复写后的最后一位数字
            while(cur < len){
                if(arr[cur] == 0){
                    dest += 2;
                }else {
                    dest++;
                }
                if(dest >= len - 1){
                    break;
                }
                cur++;
            }
            if(dest == len){
                arr[len - 1] = 0;
                cur--; dest -= 2;
            }
            while(cur >= 0){
                if(arr[cur] != 0){
                    arr[dest--] = arr[cur--];
                }else {
                    arr[dest--] = 0;
                    arr[dest--] = 0;
                    cur--;
                }
            }
        }
    }
    //leetcode 680.验证回文串Ⅱ
    class Solution {
        public boolean validPalindrome(String s) {
            int n = 0;
            int num = 0;
            int left = 0;
            int right = s.length() - 1;
            while(left <= right){
                char c1 = s.charAt(left);
                char c2 = s.charAt(right);
                if(c1 != c2){
                    if(num == 0){
                        num++;
                        right--;
                        continue;
                    }
                    n++;
                    break;
                }
                left++;
                right--;
            }
            left = 0;right = s.length() - 1;num = 0;
            while(left <= right){
                char c1 = s.charAt(left);
                char c2 = s.charAt(right);
                if(c1 != c2){
                    if(num == 0){
                        num++;
                        left++;
                        continue;
                    }
                    n++;
                    break;
                }
                left++;
                right--;
            }
            return !(n == 2);
        }
    }
}
